package org.dydl.controller.system;

import org.dydl.common.dto.ResponseMessage;
import org.dydl.model.system.SysCustomer;
import org.dydl.service.system.ISysCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 客户管理Controller
 * 
 * @author 张华城
 */

@RestController
@RequestMapping("/api/customer")
public class CustomerController {

	
	@Autowired
	private ISysCustomerService customerService;
	/**
	 * 分页、根据客户全称模糊查询客户列表
	 * @param page
	 * @param rows
	 * @param fullName
	 * @return
	 */
	@RequestMapping("/getlist")
	public ResponseMessage list(int page, int rows, String fullName){
		
		ResponseMessage res = customerService.getSysCustomerList(page, rows, fullName);

		return res;
		
	}
	/**
	 * 添加客户
	 * @param sysCustomer
	 * @return
	 */
	@RequestMapping("/save")
	public ResponseMessage save(@RequestBody SysCustomer sysCustomer){
		
		ResponseMessage res = customerService.save(sysCustomer);
		
		return res;
		
	}

	/**
	 * 删除客户
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	public boolean delete(int[] ids){
		if (ids.length != 0) {
			for (int i = 0; i < ids.length; i++) {
				customerService.delete(ids[i]);
			}
			return true;
		} else {
			return false;
		}
		
	}
}
